-
Notifications
You must be signed in to change notification settings - Fork 176
Enable check for using GC on Image in unsupported use cases #1979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable check for using GC on Image in unsupported use cases #1979
Conversation
a3d9ee5
to
84840bc
Compare
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that printing to system out is appropriate here.
Either it is an error, then we should throw an exception or it should simply be ignored.
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java
Outdated
Show resolved
Hide resolved
6ae9927
to
0e1052e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks now better using the error handler, but I think the message must be enhanced, e.g. it should explain what is the alternative to use instead.
Just a assume a common use-case, where I load an Image from a file, not I want to draw some test/watermark on it and save it again. How is this supposed to work? At best we add a new snippet that shows best practice on how to perform image modifications "the supported way" and then reference it in the message.
43c3c14
to
9b16a66
Compare
@laeubi I have added a snippet to demonstrate on how to use Image(Display, ImageGcDrawer, int, int) to load an image to the system and draw watermark over it (supported for all zoom level images. Also I have again changed the condition to only log an error when using the strict mode. This was done as per @HeikoKlare suggestion since Display#setRuntimeExceptionHandler handler contract states to only use it whenever an exception is thrown by a listener or external callback function and this is not the case here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some comments but in general I am fine with the proposed change.
Also I have again changed the condition to only log an error when using the strict mode. This was done as per @HeikoKlare suggestion since Display#setRuntimeExceptionHandler handler contract states to only use it whenever an exception is thrown by a listener or external callback function and this is not the case here.
To clarify this: it's not (only) about the specified usage scenario of the runtime exception handler but also about how this debug information may be used. I don't see that anyone will inspect the error log view of tested products, configure a different handler for runtime exceptions at the display to find such errors or the like, so the logging capability will likely remain unused. There is already some other logging guarded behind the strictChecks
property, which one can just activate for a product under test to then inspect the logs of, e.g., Jenkins builds, test runs etc.
We may think of improving the way in which the collection of debug information for strictChecks
is done in general, but since all other places currently use standard output, we should stick with it here to have a uniform way of logging that information and may do that as a separate step for all affected places.
examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet384.java
Outdated
Show resolved
Hide resolved
examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet384.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java
Outdated
Show resolved
Hide resolved
Whenever something goes wrong I go to the error log and I also report incidents from there, others do as well, so I don't see this a general problem.
Also SWT can be used standalone so its hard to tell how people actually use it. In any case if no one is looking at the errors, then my initial recommendation stays: simply don't log this. If it is important enough for people, they will do. |
If we guard this behind strict checks (like we do for all comparable checks), it will only pop-up in the error log if you enable strict checks, and I guess that usually no one does not.
The strict checks are an ability for developers to run an application with, as the name says, with more strict checks. You have to explicitly enable them to validate your application (manually or via automated tests) regarding those checks. The information is not that relevant for a consumer of an application (who sees the error log and may use the information to report a bug if it annoys them) but just for developers who can simply activate those strict checks to have further validation of an application. This is the same for the other existing strict checks. So why shouldn't we provide the ability to check an application regarding the risk of imperfect images or why should we introduce a different means of identifying them than the other strict checks we have? |
b045303
to
b591dd8
Compare
6ed864d
to
2c04d53
Compare
With this change, warnings will be logged when strict checks are enabled and a GC is initialized for an image in unsupported cases: 1. images whose scaled variants are not derived via scaling from an original version but are retrieved from a central data source (like ImageDataProvider or ImageFileNameProvider) 2. images for which handles in other zoom values have already been created such that drawing on them will only be applied to one of those handles
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rebased on master resolving conflicts due to a snippet with the same name meanwhile being added. I also slightly adapted the implementation.
Change is now fine for me. @laeubi do you have any remaining concerns or can we merge this for M3?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now. I assume there will be a N&N for SWT already to make users generally aware of ImageDrawer
so this seems suitable here.
Thank you! |
Logging a warning for GC initialized with unsupported use cases.
Examples
Run this examples with following VM arguments